package com.example.user3.demo.pattern.observer

class Observable{
    //观察者集合
    private val observerList= mutableListOf<Observer>()

    //订阅方法
    fun subscribe(observer: Observer){
        observerList.add(observer)
    }

    //通知所有观察者
    fun notifyObserver(){
        observerList.forEach {
            it.change()
        }
    }
}